home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 3 PutContentsIn Igor Pro Folder / Technical Notes / Igor Tech Notes / TN005 Stat x-tests / x-tests TEXT < prev   
Text File  |  1990-05-09  |  3KB  |  98 lines

  1.  
  2. | Given the arrays w1 and w2, this routine returns Student's t as U_t
  3. | and its significance as U_prob.  See Numerical Recipes section 13.4 for more info.
  4. | The data arrays are assumed to be drawn from populations with the same true variance.
  5. |
  6. Macro ttest(w1,w2)
  7.     string w1,w2
  8.     Prompt w1,"array 1",popup WaveList("*",";","")
  9.     Prompt w2,"array 2",popup WaveList("*",";","")
  10. ;
  11.     Silent 1
  12.     WaveStats/Q $w1
  13.     Variable ave1=V_avg, var1= V_sdev^2, n1= V_npnts
  14.     WaveStats/Q $w2
  15.     Variable ave2=V_avg, var2= V_sdev^2, n2= V_npnts
  16.     Variable df= n1+n2-2                                    | Degrees of freedom
  17.     Variable svar= ((n1-1)*var1+(n2-1)*var2)/df        | Pooled variance
  18.  
  19.     Variable/G U_t= (ave1-ave2)/sqrt(svar*(1/n1 + 1/n2))
  20.     Variable/G U_prob= betai(0.5*df,0.5,df/(df+U_t^2))
  21. End
  22.  
  23. | Given the arrays w1 and w2, this routine returns Student's t as U_t
  24. | and its significance as U_prob.  See Numerical Recipes section 13.4 for more info.
  25. | The data arrays are allowed to be drawn from populations with unequal variances.
  26. |
  27. Macro tutest(w1,w2)
  28.     string w1,w2
  29.     Prompt w1,"array 1",popup WaveList("*",";","")
  30.     Prompt w2,"array 2",popup WaveList("*",";","")
  31. ;
  32.     Silent 1
  33.     WaveStats/Q $w1
  34.     Variable ave1=V_avg, var1= V_sdev^2, n1= V_npnts
  35.     WaveStats/Q $w2
  36.     Variable ave2=V_avg, var2= V_sdev^2, n2= V_npnts
  37.  
  38.     Variable/G U_t= (ave1-ave2)/sqrt(var1/n1+var2/n2)
  39.     Variable df= (var1/n1+var2/n2)^2/((var1/n1)^2/(n1-1) + (var2/n2)^2/(n2-1))^2
  40.     Variable/G U_prob= betai(0.5*df,0.5,df/(df+U_t^2))
  41. End
  42.  
  43. | Given the PAIRED arrays w1 and w2, this routine returns Student's t as U_t
  44. | and its significance as U_prob.  See Numerical Recipes section 13.4 for more info.
  45. |
  46. Macro tptest(w1,w2)
  47.     string w1,w2
  48.     Prompt w1,"array 1",popup WaveList("*",";","")
  49.     Prompt w2,"array 2",popup WaveList("*",";","")
  50. ;
  51.     Silent 1
  52.     WaveStats/Q $w1
  53.     Variable ave1=V_avg, var1= V_sdev^2, n1= V_npnts
  54.     WaveStats/Q $w2
  55.     Variable ave2=V_avg, var2= V_sdev^2, n2= V_npnts
  56.     if( n1!=n2)
  57.         Abort "tptest: Data arrays must be paired."
  58.     endif
  59.  
  60.     Duplicate $w1 tptest_tmp1                    | Note use of wave operations to avoid macro loop
  61.     tptest_tmp1= ($w1-ave1)*($w2-ave2)
  62.     Variable df= n1-1
  63.     WaveStats/Q tptest_tmp1
  64.     Variable cov= V_avg*n1/df
  65.     KillWaves tptest_tmp1
  66.  
  67.     Variable sd= sqrt((var1+var2-2*cov)/n1)
  68.     Variable/G U_t= (ave1-ave2)/sd
  69.     Variable/G U_prob= betai(0.5*df,0.5,df/(df+U_t^2))
  70. End
  71.  
  72. | Given the arrays w1 and w2, this routine returns the value of F as U_F
  73. | and its significance as U_prob.  See Numerical Recipes section 13.4 for more info.
  74. |
  75. Macro Ftest(w1,w2)
  76.     string w1,w2
  77.     Prompt w1,"array 1",popup WaveList("*",";","")
  78.     Prompt w2,"array 2",popup WaveList("*",";","")
  79. ;
  80.     Silent 1
  81.     WaveStats/Q $w1
  82.     Variable ave1=V_avg, var1= V_sdev^2, n1= V_npnts
  83.     WaveStats/Q $w2
  84.     Variable ave2=V_avg, var2= V_sdev^2, n2= V_npnts
  85.     
  86.     if( var1 > var2 )
  87.         Variable/G U_F= var1/var2
  88.         Variable df1= n1-1, df2= n2-1
  89.     else
  90.         Variable/G U_F= var2/var1
  91.         Variable df1= n2-1, df2= n1-1
  92.     endif
  93.     Variable/G U_prob= 2*betai(0.5*df2,0.5*df1,df2/(df2+df1*U_F))
  94.     if( U_prob > 1 )
  95.         U_prob= 2-U_prob
  96.     endif
  97. End
  98.